﻿@using Huirui.Cavan.Domain.MainBoundedContext.SystemModule
@model Huirui.Cavan.Presentation.ViewModel.SystemModule.IUserAccountViewModel
@{Layout = null;}
@using (Html.BeginForm(ActionConst.ADD, ControllerConst.USERACCOUNT))
{
    <div class="tool_bar">
        <input id="useraccount_save" type="submit" style="display: none;" />
        <input id="useraccount_reset" type="reset" style="display: none" />
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'" onclick="javascript:$('#useraccount_save').click()">保存</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-undo'" id="useraccountReset">重置</a>
        <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-collapse'" onclick="toggleHeard()">折叠/展开</a>
    </div>
    <table class="form_heard">
        <tr>
            <td class="c100">
                <label>用户名:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.Name, new { id = "useraccount_name", @class = "withprompt" })
                @Html.HiddenFor(m => m.Item.Id, new { id = "useraccount_Id" })
            </td>
            <td class="c100">
                <label>密码:</label>
            </td>
            <td class="c160">
                @Html.PasswordFor(m => m.Item.Password, new { id = "useraccount_password", @class = "withprompt" })
            </td>
            <td class="c100">
                <label>对应职员:</label>
            </td>
            <td class="c160">
                @Html.TextBoxFor(m => m.Item.Employee.Name, new { id = "useraccount_employeeName", @class = "withprompt" })
                @Html.HiddenFor(m => m.Item.Employee.Id, new { id = "useraccount_employeeCode", @class = "withprompt" })
            </td>
                        <td class="c100">
                <label>状态:</label>
            </td>
            <td class="c160">
                @Html.RadioButtonFor(m => m.IsLocked, "0", new { id = "useraccount_lock", @class = "withprompt" })@Html.Raw("启用")
                @Html.RadioButtonFor(m => m.IsLocked, "1", new { id = "useraccount_unlock", @class = "withprompt" })@Html.Raw("停用")
            </td>
        </tr>
    </table>
}
<table id="useraccount_dg">
</table>
<div id="useraccounttb">
    @*<a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" id="deleteUserAccount">批量删除</a>*@
    <a href="#" class="easyui-linkbutton" iconcls="icon-save" plain="true" onclick="javascript:alert('引出')">引出</a>
</div>
@{ Html.RenderAction(ActionConst.SEARCH, ControllerConst.EMPLOYEE, new { purpose = "ForUserAccount" }); }
<script type="text/javascript">
    $(function () {
        $("form[action^='/useraccount/add']").submit(function () {
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (data) {
                    if (data.IsSuccess) {
                        $('#useraccount_dg').datagrid('reload');
                    }
                },
                error: function () {
                    alert('系统繁忙，请稍候再试');
                }
            })

            return false;
        });

        $('#useraccount_dg').datagrid({
            class: 'easyui-datagrid',
            title: "账号列表",
            idField: 'Id',
            singleSelect: 'true',
            fitColumns: true,
            url: "/useraccount/list",
            toolbar: '#useraccounttb',
            columns: [[
              { field: 'IsSelected', title: '选择', width: 60, checkbox: true },
              { field: 'Name', title: '名称', width: 100 },
              { field: 'Password', title: '密码', width: 100 },
              { field: 'Employee', title: '对应职员', width: 100 },
              { field: 'Status', title: '启用', width: 100 }
            ]],
            onClickRow: function (rowIndex, rowData) {
                $("#useraccount_Id").val(rowData.Id);
                $("#useraccount_name").val(rowData.Name);
                $("#useraccount_password").val(rowData.Password);
                $("#useraccount_employeeName").val(rowData.Employee);
                $("input[name='IsLocked'][value='" + rowData.IsLocked + "']").attr('checked', 'true');
                $("input").css('color', '#333333');
            }
        });

        //$("#deleteUserAccount").bind("click", function () {
        //    if ($('#useraccount_dg').datagrid('getChecked').length) {
        //        var selected = $('#useraccount_dg').datagrid('getChecked');

        //        var effectRow = new Object();
        //        if (selected.length) {
        //            effectRow["selected"] = JSON.stringify(selected);
        //        }

        //        $.post("/useraccount/delete", effectRow, function (data) {
        //            if (data.IsSuccess) {
        //                $('#useraccount_dg').datagrid('reload');
        //                $('#useraccount_dg').datagrid('clearChecked');
        //            }
        //        }, "JSON").error(function () {
        //            $.messager.alert("提示", "网络异常，请稍候再试");
        //        });
        //    }
        //});

        $("#useraccountReset").bind("click", function () {
            $('#useraccount_reset').click();
            $("#useraccount_Id").val("0");
        });


        $("#useraccount_employeeName").bind("click", function () {
            InitSelectEmployee('employeesForUserAccount');
            openWindow("selectEmployeeWindowForUserAccount");
        });

        $("#searchEmployeeForUserAccount").submit(function () {
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result) {
                    if (result.total > 0) {
                        $('#employeesForUserAccount').datagrid({
                            data: result,
                            checkOnSelect: true,
                            selectOnCheck: true
                        });
                    }
                },
                error: function () {
                    alert('系统繁忙，请稍候再试');
                }
            })

            return false;
        });

        $("#doSelectEmployeeForUserAccount").bind("click", function () {
            var currentRow = $('#employeesForUserAccount').datagrid('getSelected');
            $("#useraccount_employeeCode").val(currentRow.Id);
            $("#useraccount_employeeName").val(currentRow.Name);
            closeWindow("selectEmployeeWindowForUserAccount");
        });
    });
</script>
